<template>
  <!-- 输入框 -->
  <header class="header">
    <h1>TodoList</h1>
    <input 
    @keyup.enter="handleAdd"
    placeholder="请输入任务" class="new-todo" v-model="todoName" />
    <button class="add" @click="handleAdd">添加任务</button>
  </header>
</template>

<script>
export default {
  data() {
    return {
      todoName: ''
    }
  },
  methods: {
    // 添加功能
    handleAdd() {
      if(this.todoName.trim() === ''){
        alert('请输入内容')
        return
      }
      this.$emit('add',this.todoName)
      this.todoName=''
    }
  }
}
</script>

<style></style>
